<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet"
	href="${contextPath}/static/statistics/css/mui.min.css">
<link rel="stylesheet"
	href="${contextPath}/static/statistics/css/app.css" />
<link rel="stylesheet"
	href="${contextPath}/static/statistics/layui/css/layui.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<a class="mui-title">店铺异常举报</a>
	</header>
	<div class="mui-content">
		<div class="mui-card">
			<div class="mui-collapse-content" id="addCyry_box">
				<input type="hidden" id="hideId" name="compId" />
				<input type="hidden" id="userId" name="userId" />
				<input type="hidden" id="custCode" name="custCode" />
				<div class="mui-card-header">
					客户名称：
					<p id="p_custname"></p>
				</div> 
				<div class="mui-card-header">
					店铺名称：
					<p id="p_shopname"></p>
				</div>
				<div class="mui-card-header">
					举报类型：
					<select id="exceptype" name="exceptype" style="width:60%">
						<option value="1">假私非烟品</option>
						<option value="2">营销异动 </option>
						<option value="3">消费者投诉</option>
					</select>
				</div> 
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p>一.图片上传</p>
						<img class="layui-upload-img"" alt="" src="${contextPath}/static/image/uploadimg.jpg"
							name="sfzxx" id="p_sfzzm" style="width:150px;height:100px;border-raidus:10px" />
						<input type="text" name="fileStr" id="fileStr" style="display:none" />
						<input type="text" name="fileType" id="fileType" style="display:none" />
						
					</div>
				</div>
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<p>二.举报类容</p>
						<div class="mui-input-row" style="margin:10px 5px">
							<textarea id="p_shopDescribe" rows="5" placeholder="请输入举报内容,至少输入10个字符"></textarea>
						</div>
					</div>
				</div>
				<div class="mui-card-footer" style="justify-content:flex-end;-webkit-justify-content:flex-end">
					<button onclick="saveBaseInfo()" class="mui-btn" >提交举报</button>
				</div>
			</div>
		</div>
	</div>
	<script src="${contextPath}/static/statistics/js/mui.min.js"></script>
	<script src="${contextPath}/static/statistics/js/jquery.js"></script>
	<script src="${contextPath}/static/statistics/layui/layui.js"></script>
	<script src="${contextPath}/static/statistics/layui/layui.all.js"></script>
	<script type="text/javascript">
		mui.init({
			swipeBack : true
		});
		window.onload = function(){
			var shopid = '${shopid}';
			var userid = '${userid}';
			$.ajax({
				type : "POST",
				url : "${contextPath}/Honest/ShopInfor",
				data : {
					"shopid" : shopid
				},
				dataType : "json",
				async : false,
				success : function(data) {
					$("#hideId").val(shopid);
					$("#userId").val(userid);
					$("#custCode").val(data.data.CUST_CODE);
					$("#p_custname").text((data.data.CUST_NAME));
					$("#p_shopname").text((data.data.SHOP_NAME));
				}
			});
		}
		var nativeWebview, imm, InputMethodManager;
		var initNativeObject = function(){
			if (mui.os.android){
				var main = plus.android.runtimeMainActivity();
				var Context = plus.android
						.importClass("android.content.Context");
				InputMethodManager = plus.android
						.importClass("android.view.inputmethod.InputMethodManager");
				imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
			} else {
				nativeWebview = plus.webview.currentWebview()
						.nativeInstanceObject();
			}
		}
		var showSoftInput = function() {
			if (mui.os.android) {
				imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
			} else {
				nativeWebview.plusCallMethod({
					"setKeyboardDisplayRequiresUserAction" : false
				});
			}
		};
		mui.plusReady(function() {
			initNativeObjects();
			showSoftInput();
		});
		function saveBaseInfo() {
			var exceptioninfo = $("#p_shopDescribe").val();
			if(exceptioninfo.length < 10){
				layer.msg('举报类容至少10个字符')
				return;
			}
			var queryModel = {
			}
			queryModel.fileStr = $("#p_sfzzm").attr('src'); 
            queryModel.fileType = 'jpg';
            queryModel.fileStart = "3";
            layer.load(1)
            $.ajax({
                type: 'POST',
                url: '${contextPath}/sys/cloudling/submitImg',
                data: queryModel,
                dataType: 'json',
                success: function (data) {
                    if (data.success == false){
                        return
                    }else{
                    	var imgsrc=data.data;
                    	submit(imgsrc);
                        layer.closeAll('loading');
                    }
                    var dataArray = data.data;
                },
                error: function (result) {
                	layer.msg('false');
                }
            });
		}
		function submit(imgsrc){
			var shopid = $("#hideId").val();
			var userid = $("#userId").val();
			var custcode = $("#custCode").val();
			var custname = $("#p_custname").text();
			var shopname = $("#p_shopname").text();
			var exceptioninfo = $("#p_shopDescribe").val();
			var exceptype = $("#exceptype").val();
			var picture = imgsrc;
			$.ajax({
				type : "post",
				url : "${contextPath}/Honest/saveInfo",
				async : true,
				data : {
					"shopid" : shopid,
					"shopname" : shopname,
					"exceptioninfo" :exceptioninfo,
					"picture" :picture,
					"userid" : userid,
					"ccode" :custcode,
					"cname" : custname,
					"exceptype" : exceptype
				},
				success : function(data) {
					if (data.message == 'success') {
						layer.msg('操作成功');
						closeme();
					}else{
						layer.msg('操作失败');
					}
				},
				error : function() {
					layer.msg('操作失败');
				}
			});
		}

		function closeme() {
			 //window.location.href = "${contextPath}/Honest/exceptionReport"
		} 
		layui.use('upload', function() {
			var upload = layui.upload;
			/*上传附件照片*/
			var uploadSfzzm = upload.render({
				elem : '#p_sfzzm' //绑定元素
				,
				//这里有问题
				url : '${contextPath}/upload',
				auto : false,
				choose : function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result) {
						$('#p_sfzzm').attr('src', result); //图片链接（base64）
					});
				},
				done : function(res) {
					//如果上传失败
					if (res.code > 0) {
						return layer.msg('上传失败');
					}
					//上传成功
				},
				error : function() {
					//失败
				}
			});

		});
	</script>
</body>
</html>